package controller;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

import model.Client;
import model.Email;
import model.Server;


/**
 * This class takes an array list of email objects and dispatches them
 * to the respective clients if they are online. If they are not online, 
 * it saves them into persistent so when the clients will come online next time,
 * they will pull them.
 * 
 * @author MUSAB
 *
 */
public class EmailDispatcher implements Runnable {

	/**
	 * The list of emails to be dispatched
	 */
	private ArrayList<Email> emailsToDispatch;
	
	
	/**
	 * Reference to the server model
	 */
	private Server server;
	
	/**
	 * Constructor
	 * 
	 * @param emailsToDispatch
	 */
	public EmailDispatcher(ArrayList<Email> emailsToDispatch, Server server){
		
		this.emailsToDispatch = emailsToDispatch;
		this.server = server;
	}

	/**
	 * Check the clients who are online and sent them their emails
	 */
	@Override
	public void run() {
		dispatchEmails();
	}

	
	
	
	
	/**
	 * Dispatches the emails or saves them if the client is not online
	 */
	private synchronized void dispatchEmails() {
		
		
	}
}
